package com.fjh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjh.domain.PickAddr;
import com.fjh.service.impl.PickAddrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("shop/pickAddr")
@Api(tags = "自提点管理")
public class PickAddrController {

    @Autowired
    private PickAddrService pickAddrService;

    @GetMapping("page")
    @ApiOperation("分页查询自提点")
    @PreAuthorize("hasAuthority('shop:pickAddr:page')")
    public ResponseEntity<Page<PickAddr>> loadPickAddrPage(Page<PickAddr> page,PickAddr pickAddr){
        Page<PickAddr> pickAddrPage = pickAddrService.loadPickAddrPage(page,pickAddr);
        return ResponseEntity.ok(pickAddrPage);
    }

    @PostMapping
    @ApiOperation("新增自提点")
    @PreAuthorize("hasAuthority('shop:pickAddr:save')")
    public ResponseEntity<Void> addPickAddr(@RequestBody PickAddr pickAddr) {
        pickAddrService.save(pickAddr);
        return ResponseEntity.ok().build();
    }
}
